﻿///----------------------------------------------------------------
/// Copyright (C) 2008-2010 yyssoft
/// 版权所有。
///
/// 文件名：XMK_A_Z_SY03DAL.cs
/// 文件功能描述：XMK_A_Z_SY03数据访问类
///
///
/// 创建标识：yyssoft 2014/5/19
///
/// 修改标识：
/// 修改描述：
///
/// 修改标识：
/// 修改描述：
///---------------------------------------------------------------
using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using XMK.Tadong.Model;
using XMK.Framework.DataAccess;

namespace XMK.Tadong.DAL
{
    /// <summary>
    /// XMK_A_Z_SY03的数据访问类
    /// </summary>
    public class XMK_A_Z_SY03DAL
    {

        #region  构造函数
        protected DbProvider dbProvider;
        public XMK_A_Z_SY03DAL(DbProvider dbProvider)
        {
            this.dbProvider = dbProvider;
        }
        #endregion  构造函数

        #region  成员方法

        /// <summary>
        /// 判断是否已有数据
        /// </summary>
        public bool IsExist(string sql)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(sql);
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, strSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            object obj = DbManager.ExecScalar(cmd);

            return (Convert.ToInt16(obj) != 0);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        /// <param name="model">实体对象</param>
        /// <returns>成功返回主标识ID,失败返回"0"</returns>
        public bool AddBySql(XMK_A_Z_SY03Info model)
        {
            StringBuilder sbSql = new StringBuilder();
            sbSql.Append(@" INSERT INTO XMK_A_Z_SY03 
					(JH,DINGJSD,DIJSD,HD,AVER,LJHD,SDB,CW,DLX,DLY,DJDM) 
					VALUES(:p_JH,:p_DINGJSD,:p_DIJSD,:p_HD,:p_AVER,:p_LJHD,:p_SDB,:p_CW,:p_DLX,:p_DLY,:p_DJDM)");

            bool result = true;

            //新建一个数据库操作帮助类
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, sbSql.ToString(),
                //参数生成
                delegate()
                {
                    return DbCmdHelper.CreateParameters(dbProvider, "JH", "DINGJSD", "DIJSD", "HD", "AVER", "LJHD", "SDB", "CW", "DLX", "DLY", "DJDM").ToArray();
                });
            //参数设值
            cmd.SetParamValues(model.JH, model.DINGJSD, model.DIJSD, model.HD, model.AVER, model.LJHD, model.SDB, model.CW, model.DLX, model.DLY, model.DJDM);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            int back = DbManager.ExecNonQuery(cmd);
            if (back == 0)
                result = false;

            return result;
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        /// <param name="File_ID">文件编号</param>
        /// <returns>成功返回true,失败返回false</returns>
        public bool DeleteBySql(string sql)
        {
            //string strSQL = @" delete from XMK_A_Z_SY03 where File_ID=" + ID + "";

            bool result = true;

            //新建一个数据库操作帮助类
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, sql);
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            int back = DbManager.ExecNonQuery(cmd);
            if (back == 0)
                result = false;

            return result;

        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public DataTable GetModelBySql(int ID)
        {
            StringBuilder sbSql = new StringBuilder();
            sbSql.Append(@"SELECT ID,JH,DINGJSD,DIJSD,HD,AVER,LJHD,SDB,CW,DLX,DLY,DJDM 
					FROM XMK_A_Z_SY03 WHERE ID=" + ID + " ");
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, sbSql.ToString());
            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataTable ds = DbHelper.ExecFullDataTable(cmd.DbProvider, cmd.DbCmdInfo);
            if (ds != null)
            {
                return ds.Copy();
            }
            return null;
        }


        //通过筛选条件获取数据
        public DataSet GetDataByWhere(string strWhere)
        {
            StringBuilder sbSql = new StringBuilder();
            sbSql.Append(@"SELECT * FROM XMK_A_Z_SY03  where 1=1 " + strWhere);
            DbCmdHelper cmd = new DbCmdHelper(dbProvider, sbSql.ToString());

            cmd.DbCmdInfo.CommandType = CommandType.Text;
            DataSet ds = DbHelper.ExecFullDataSet(cmd.DbProvider, cmd.DbCmdInfo);

            return ds;
        }

        #endregion  成员方法

    }
}

